package backstage.product;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import shops.ProductItem_Back;

public class productInfo {
    private int checkid;
    private int checkid_2;
    private int id;
    //輸出至前端網頁
    private String title; 
    private shops.ProductItem_Back productItem_Back;  
    private TreeMap<Integer,String> typeResult;
    private TreeMap<Integer,String> supplyResult;
        
    public productInfo() {
    }
    
    public String execute() throws Exception {
     
        NWDB.NWDB mydb=new NWDB.NWDB();
        NWDB.IProduct ip=new NWDB.ImplProduct(mydb.getConnection());
        mydb.setIProduct(ip);
        
        HttpServletRequest request=ServletActionContext.getRequest();         
        checkid=mydb.GetAllProductCount();
      //checkid_2=Integer.parseInt(request.getParameter("id"));
      // System.out.println(request.getParameter("id"));
       if(request.getParameter("id")!=null) 
       {this.id=Integer.parseInt(request.getParameter("id"));}
       
        if(this.id==0)
            this.setTitle("新增產品");
        else
        {
            this.setTitle("修改產品");        
            HashMap<String,Object> hm=mydb.GetProductItemById_Back(id);            
            this.productItem_Back=new shops.ProductItem_Back();
            this.productItem_Back.setId(id);
            this.productItem_Back.setName(hm.get("name").toString());
            this.productItem_Back.setPrice((Integer)hm.get("price"));
            this.productItem_Back.setStock((Integer)hm.get("stock"));
            this.productItem_Back.setSale((Byte)hm.get("sale"));
            this.productItem_Back.setTypeId((Integer)hm.get("typeId"));
            this.productItem_Back.setTypeName(hm.get("typeName").toString());
            this.productItem_Back.setClick_count((Integer)hm.get("click_count"));
            this.productItem_Back.setDescription(hm.get("description").toString());  
     /*  this.productItem_Back.setPic((byte[])hm.get("pic"));
            this.productItem_Back.setPic_1((byte[])hm.get("pic_1"));
            this.productItem_Back.setPic_2((byte[])hm.get("pic_2"));
            this.productItem_Back.setPic_3((byte[])hm.get("pic_3"));
     */
        }
        
        this.typeResult=mydb.GetProductType();
     //   this.supplyResult=mydb.GetSupplyCompany();
        mydb.close();        
        return "success";        
    }

    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    
    public TreeMap<Integer,String> getTypeResult() {
        return typeResult;
    }
    public void setTypeResult(TreeMap<Integer,String> typeResult) {
        this.typeResult = typeResult;
    }

    public TreeMap<Integer,String> getSupplyResult() {
        return supplyResult;
    }
    public void setSupplyResult(TreeMap<Integer,String> supplyResult) {
        this.supplyResult = supplyResult;
    }   
   
   public ProductItem_Back getProductItem_Back() {
        return productItem_Back;
    }

    public void setProductItem_Back(ProductItem_Back productItem_Back) {
        this.productItem_Back = productItem_Back;
    }
          
    public int getCheckid() {
        return checkid;
    }

    public void setCheckid(int checkid) {
        this.checkid = checkid;
    }

    public int getCheckid_2() {
        return checkid_2;
    }

    public void setCheckid_2(int checkid_2) {
        this.checkid_2 = checkid_2;
    }
    
}
